package com.computercourse.learning.controller;

import com.computercourse.framework.domain.learning.respones.*;
import com.computercourse.framework.model.response.ResponseResult;
import com.computercourse.learning.service.LearningService;
import com.computercourse.api.learning.CourseLearningControllerApi;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Feng.Yuan
 * @description
 * @date 2020/2/1 5:08 下午
 * @return
 */
@RestController
@RequestMapping("/learning/course")
public class CourseLearningController implements CourseLearningControllerApi {

    @Autowired
    LearningService learningService;

    @Override
    @GetMapping("/getmedia/{courseId}/{teachplanId}")
    public GetMediaResult getMedia(@PathVariable("courseId") String courseId,
                                   @PathVariable("teachplanId") String teachplanId) {

        return learningService.getMedia(courseId, teachplanId);
    }
    @GetMapping("/chooseCourse/{page}/{size}/{userId}")
    public GetChooseCourseResult getChooseCourseList(@PathVariable("page") Integer page,
                                                     @PathVariable("size") Integer size , @PathVariable("userId")String userId) {

        if(page >= 1){
            page = 0;
        }
        return learningService.getChooseCourseList(page, size,userId);
    }


    @Override
    @GetMapping("/getNote/{courseId}")
    @ApiOperation(value = "获取该课程所有笔记")
    public GetLearningNoteResult getAllNotes(@PathVariable("courseId") String courseId) {

        return learningService.getAllNotesList(courseId);

    }

    @Override
    @GetMapping("/getNote/perfect/{courseId}")
    @ApiOperation(value = "获取该课程所有精选笔记")
    public GetLearningNoteResult getAllPerfectNotes(@PathVariable("courseId") String courseId) {
        return learningService.getAllPerfectNotes(courseId);
    }

    @Override
    @DeleteMapping("/delete/note/{courseId}/{noteId}")
    @ApiOperation(value = "删除该条笔记")
    public ResponseResult deleteNote(@PathVariable("courseId") String courseId,@PathVariable("noteId") String noteId) {
        return learningService.deleteNoteByCourseIdAndNoteId(courseId,noteId);
    }

    @Override
    @PostMapping("/save/note/{courseId}/{noteContent}")
    @ApiOperation(value = "保存该条笔记")
    public ResponseResult saveNote(@PathVariable("courseId") String courseId,@PathVariable("noteContent")String noteContent) {
        return learningService.saveNote(courseId,noteContent);

    }

    @Override
    @PostMapping("/save/perfect/note/{courseId}/{noteId}")
    @ApiOperation(value = "设为精选笔记")
    public ResponseResult saveAsPerfectNote(@PathVariable("courseId") String courseId,@PathVariable("noteId")String noteId) {
        return learningService.saveAsPerfectNoteByCourseId(courseId,noteId);

    }


    @Override
    @PostMapping("/save/answer/{courseId}/{answerTitle}/{answerContent}")
    @ApiOperation(value = "保存该条回答")
    public ResponseResult saveAnswer(@PathVariable("courseId") String courseId,@PathVariable("answerTitle")String answerTitle,@PathVariable("answerContent")String answerContent) {
        return learningService.saveAnswer(courseId,answerTitle,answerContent);

    }

    @Override
    @PostMapping("/save/perfect/answer/{courseId}/{answerId}")
    @ApiOperation(value = "设为精选回答")
    public ResponseResult saveAsPerfectAnswer(@PathVariable("courseId") String courseId,@PathVariable("answerId")String answerId) {
        return learningService.saveAsPerfectAnswerByCourseId(courseId,answerId);

    }

    @Override
    @DeleteMapping("/delete/answer/{courseId}/{answerId}")
    @ApiOperation(value = "删除该条回答")
    public ResponseResult deleteAnswer(@PathVariable("courseId") String courseId,@PathVariable("answerId") String answerId) {

        return learningService.deleteNoteByCourseIdAndAnswerId(courseId,answerId);

    }

    @Override
    @GetMapping("/getAnswer/{courseId}")
    @ApiOperation(value = "获取该课程所有回答")
    public GetLearningAnswerResult getAllAnswer(@PathVariable("courseId") String courseId) {

        return learningService.getAllAnswersList(courseId);

    }

    @Override
    @GetMapping("/getAnswer/perfect/{courseId}")
    @ApiOperation(value = "获取该课程所有精选回答")
    public GetLearningAnswerResult getAllPerfectAnswers(@PathVariable("courseId") String courseId) {
        return learningService.getAllPerfectAnswers(courseId);
    }

    @Override
    @GetMapping("/getComment/{courseId}")
    @ApiOperation(value = "获取该课程所有评论")
    public GetLearningCommentResult getAllComment(@PathVariable("courseId") String courseId) {
        return learningService.getAllCommentList(courseId);

    }

    @Override
    @PostMapping("/save/comment/{courseId}/{commentContent}/{commentCourseGrade}")
    @ApiOperation(value = "保存该条评论")
    public ResponseResult saveComment(@PathVariable("courseId") String courseId,@PathVariable("commentContent")String commentContent,@PathVariable("commentCourseGrade")Integer commentCourseGrade) {
        return learningService.saveComment(courseId,commentContent,commentCourseGrade);

    }

    @Override
    @PostMapping("/cancel/perfect/note/{courseId}/{noteId}")
    @ApiOperation(value = "取消该条精选笔记")
    public ResponseResult cancelPerfectNote(@PathVariable("courseId") String courseId,@PathVariable("noteId")String noteId) {
        return learningService.cancelNote(courseId,noteId);

    }

    @Override
    @PostMapping("/cancel/perfect/answer/{courseId}/{answerId}")
    @ApiOperation(value = "取消该条精选回答")
    public ResponseResult cancelPerfectAnswer(@PathVariable("courseId") String courseId,@PathVariable("answerId")String answerId) {
        return learningService.cancelAnswer(courseId,answerId);

    }
}
